package com.amir.common.utils

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool
import com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions

/**
 * @author Administrator.
 * @date 2020/8/11 17:22.
 * make your program better than last time.
 */
@GlideModule
class MyGlideModule : AppGlideModule() {

    override fun applyOptions(context: Context, builder: GlideBuilder) {
        val memoryCacheSizeBytes = 1024 * 1024 * 50
        val bitmapCacheSizeBytes = 1024 * 1024 * 50
        builder.setMemoryCache(LruResourceCache(memoryCacheSizeBytes.toLong()))
        builder.setBitmapPool(
            LruBitmapPool(
                bitmapCacheSizeBytes.toLong()
            )
        )
        builder.setDefaultRequestOptions(RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
        val diskCacheSizeBytes = 1024 * 1024 * 500
        builder.setDiskCache(
            ExternalPreferredCacheDiskCacheFactory(
                context, ".cache/images_cache",
                diskCacheSizeBytes.toLong()
            )
        )
        //builder.setLogLevel(Log.DEBUG)
    }

    override fun isManifestParsingEnabled(): Boolean {
        return false
    }
}